package com.scalar.chiptrack.adaptor.sitime.utac;

import com.scalar.chiptrack.jobs.JobHandler;
import com.scalar.chiptrack.adaptor.AdaptorConstants;
import com.scalar.chiptrack.adaptor.ShippedLot;
import com.scalar.chiptrack.adaptor.AssemblyLot;
import com.scalar.chiptrack.adaptor.Adaptor;
import com.scalar.chiptrack.adaptor.AdaptorUtils;
import com.scalar.chiptrack.adaptor.utils.ParserResult;
import com.scalar.chiptrack.adaptor.utils.Parser;
import com.scalar.chiptrack.adaptor.utils.ParserFactory;
import com.scalar.chiptrack.adaptor.utils.CSVParserImpl;
import com.scalar.chiptrack.adaptor.dao.AdaptorDAO;
import com.scalar.chiptrack.adaptor.dao.ShippedLotDAO;
import com.scalar.chiptrack.adaptor.dao.AdaptorRunInfo;
import com.scalar.chiptrack.utils.Logger;
import com.scalar.chiptrack.utils.StringUtils;
import com.scalar.ScalarException;

import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;

/**
 * Created by IntelliJ IDEA.
 * User: munugoti
 * Date: 2 Feb, 2011
 * Time: 9:27:37 PM
 * To change this template use File | Settings | File Templates.
 */
public class UTACNewTransactionParser extends JobHandler implements AdaptorConstants
{
    private static Logger m_parserLogger= null;
    private String m_dataOutputDir      = null;

    private HashMap<String, ShippedLot> m_shipQtyOutDataMap = new HashMap<String, ShippedLot>();
    private HashMap<String, AssemblyLot> m_receiveQtyInMap  = new HashMap<String, AssemblyLot>();
    private ArrayList<Adaptor> transactionList = new ArrayList<Adaptor>();

    public UTACNewTransactionParser() throws ScalarException
    {
        try
        {
            m_dataOutputDir = AdaptorUtils.getDataOutputDir( VENDOR_NAME_UTAC, LOCATION_TYPE_CLASS_STORE );
            AdaptorUtils.makeAllAdaptorDirs( m_dataOutputDir );
            m_parserLogger = AdaptorUtils.getDataParserLogger( m_dataOutputDir,VENDOR_NAME_UTAC );
            AdaptorDAO.setLogger( m_parserLogger );
            ShippedLotDAO.setLogger( m_parserLogger );
            AdaptorUtils.setLogger( m_parserLogger );
        }
        catch (ScalarException se)
        {
            log("ERROR!! ERROR!! ERROR!! Exception while loading/creating UTAC Trnas Parser output directory from database, Exception: " + se);
            throw se;
        }
    }
    /**
     *
     * @param args
     * @throws Exception
     */
    public static void main( String args[] ) throws Exception
    {
        try
        {
            new UTACNewTransactionParser().execute();
        }
        catch (Exception e)
        {
            throw e;
        }
    }
    //Execute Method
   public void execute() throws Exception
   {
       AdaptorUtils.printHeader(VENDOR_NAME_UTAC + " FTP", CONSTANT_PARSER );

       File doneDestDir = new File( m_dataOutputDir + "/done" );

       File wipDataoutDir = new File( m_dataOutputDir );

       File[] fileList = wipDataoutDir.listFiles();

       if ( ( fileList == null ) || ( fileList.length <= 3 ) )
       {
           log( "No file found in directory: " + wipDataoutDir );
           throw new ScalarException( "No file found in directory: " + wipDataoutDir + "----\n\n" );
       }

       ArrayList<File> successFileList   = new ArrayList<File>();
       boolean success             = false;

       try
       {
           for ( int i = 0; i < fileList.length; i++ )
           {
               if ( fileList[i].isDirectory())
               {
                   continue;
               }

               if ( ( fileList[i].getName() != null ) && fileList[i].getName().trim().startsWith( UTACNewTransactionAdaptor.FILE_NAME_TRANSACTION ) )
               {
                   parseEDIDailyTransactionReport ( fileList[i].getAbsolutePath(), fileList[i].getName() );

                   successFileList.add( fileList[i] );
               }
           }
           success = true;
       }
       catch ( Exception e )
       {
           success = false;
           log( "ERROR!! ERROR!! ERROR!! While parsing UTAC Trans Yield Report and storing File " + e );
           e.printStackTrace();
           throw e;
       }


       if ( !transactionList.isEmpty() )
       {
          AdaptorDAO.updateEDITransactionsData( null, transactionList );
       }

       try
       {
           if ( !m_receiveQtyInMap.isEmpty() )
           {
               log(" Saving the In Transaction report information");

               AdaptorDAO.saveInTransactionData( null, m_receiveQtyInMap.values().iterator() );
           }
           success = true;
       }
       catch (Exception e)
       {
           success = false;
            e.printStackTrace();
            log( "ERROR!! ERROR!! ERROR!! Could not update Assembly Yield Lot information into database: " + e );
            throw e;
       }

       try
       {
          // Save Out Transactions
          if ( m_shipQtyOutDataMap.isEmpty() == false )
          {
              log( " Updating Out Transaction Lot Information" );
              AdaptorDAO.saveOutTransactionData( null, m_shipQtyOutDataMap.values().iterator() );
          }
          success = true;
          m_shipQtyOutDataMap.clear();
          m_shipQtyOutDataMap = null;
       }
       catch (ScalarException se)
       {
          success = false;
          se.printStackTrace();
          log( "ERROR!! ERROR!! ERROR!! Could not update Out Transaction Lot information into database: " + se );
          throw se;
       }

	    int adaptor_id = AdaptorRunInfo.getLastRunAdaptorId( UTACNewTransactionAdaptor.ADAPTOR_NAME, CONSTANT_ADAPTOR);

        // Update Adaptor_Run_Info table
        try
        {
            if ( success == true )
            {
                AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, UTACNewTransactionAdaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
                System.out.println( "SUCCESSFULLY UPDATED IN THE DATABASE" );
            }
        }
        catch ( ScalarException se )
        {
            success = false; //As filES DATA SAVED , UPDATEING AS SUCCESS
            AdaptorRunInfo.saveAdaptorLastUpdatedStatus(CONSTANT_PARSER, UTACNewTransactionAdaptor.ADAPTOR_NAME, CONSTANT_SUCCESS, adaptor_id);
            log( "WARNING!! WARNING!! WARNING!! Could not update Adaptor run information, Exception: " + se );
            throw se;
        }
        // Move the successful files to 'done' directory
        if ( success )
        {
            AdaptorUtils.moveFilesToDone( successFileList, doneDestDir );
        }
    }//end of execute method

    private void parseEDIDailyTransactionReport( String fileNamePath, String fileName ) throws Exception
    {
        if ( fileNamePath == null ) throw new ScalarException( "Filename argument is null" );

        ParserResult result     = null;
        ShippedLot shippedLot   = null;
        AssemblyLot assemblyLot = null;
        String lotNumber        = null;
        String partNumber       = null;
        String fabLotNo = null;
        try
        {
            File detailWipFile = new File( fileNamePath );
            if ( detailWipFile.exists() == false )
            {
                throw new ScalarException( fileNamePath + " doesnt exist" );
            }
            
            log( "\nFound " + fileNamePath );
            log( "\nParsing the file for EDI Transaction Report..." );
            System.out.println( "\nFound " + fileNamePath );
            System.out.println( "\nParsing the file for EDI Transaction Report..." );

            String fileNames = AdaptorRunInfo.getPreviousUpdatedFileList(UTACNewTransactionAdaptor.ADAPTOR_NAME);
            String[] parsedfileName = fileNames != null ? fileNames.split("<br>"): null;
            boolean saveSheetData = true;
            if ( parsedfileName != null )
            {
                for ( int i=0; i< parsedfileName.length; i++)
                {
                     if ( parsedfileName[i].equalsIgnoreCase(fileName.substring(0, fileName.lastIndexOf(".") ) ) )
                     {
                        saveSheetData = false;
                         break;
                     }
                }
            }    
            Parser parser = ParserFactory.getCSVParser( detailWipFile, ',' );

            ((CSVParserImpl)parser).setHeaderRowIdx(0);
            ((CSVParserImpl)parser).setDataStartRowIdx(1);

            result = parser.parse();
            if ( result == null || result.getHeadings() == null)
            {
                System.out.println(" ******************** Header Row not Found ********************** ");
                return;
            }
            //System.out.println("result.getHeadings() = " + result.getHeadings());
            if ( result != null )
            {
                while ( result.next() )
                {
                    partNumber = result.getString("Customer Part#");
                    lotNumber  = result.getString("Assembly Lot");
                    fabLotNo   = result.getString("Wafer Lot");
                    String allWafers = null;
                    if ( partNumber != null && partNumber.trim().length() >0  )
                    {
                         Adaptor adaptor = new Adaptor();

                         adaptor.setTransactionCode(result.getString("Transaction Code"));
                         adaptor.setCustomerPart(partNumber);
                         adaptor.setWaferLot( fabLotNo );
                         adaptor.setWaferNo( result.getInt("Wafer No"));
                         adaptor.setDieQty( result.getInt("Die Quantity"));
                         adaptor.setTransactionTime(result.getString("Transaction Time"));
                         adaptor.setLotStatus(result.getString("Lot Status"));
                         adaptor.setWaferMapName(result.getString("Wafer Map Name"));
                         adaptor.setSystemTime(result.getString("System Time"));
                         adaptor.setShipFromPlant(result.getString("Ship From Plant"));
                         adaptor.setShipLocation(result.getString("Shipping Location"));
                         adaptor.setAssemblyLot(lotNumber);
                         adaptor.setLotDieQty( result.getInt("Lot Die Quantity") );
                         adaptor.setBachingLot( result.getString("Baching lot#") );
                         adaptor.setDateCode(result.getString("Date Code") );
                         adaptor.setVendorName( VENDOR_NAME_UTAC );
                        
                         if ( saveSheetData )
                         {
                            transactionList.add( adaptor );
                         }

                        String transDate = StringUtils.formatDate(adaptor.getTransactionTime(), "yyyyMMddHHmmss", "MM/dd/yyyy");
                        //OUT TRANSACTIONS
                        if ( adaptor.getTransactionCode() != null &&
                         ( "Assembly_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) || "Pretest_Out".equalsIgnoreCase( adaptor.getTransactionCode() )
                            || "FT_Out".equalsIgnoreCase( adaptor.getTransactionCode() )   || "TR_Out".equalsIgnoreCase( adaptor.getTransactionCode() )
                             || "TRES_IN".equalsIgnoreCase( adaptor.getTransactionCode() ) || "TRES_Out".equalsIgnoreCase( adaptor.getTransactionCode() )
                            /*|| "TFG_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) */
                            || "FG_Out".equalsIgnoreCase( adaptor.getTransactionCode() )   /*|| "Die_Out".equalsIgnoreCase( adaptor.getTransactionCode() )*/ )  )
                        {
                           if ("TR_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               if (lotNumber.indexOf("LAT") != -1 )
                               {
                                   lotNumber = lotNumber.substring(0, lotNumber.indexOf("LAT")-1 );
                               }
                               //System.out.println("TR_Out lotNumber = " + lotNumber);
                           }
                           if ("Pretest_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               if (lotNumber.indexOf("_") != -1 )
                               {
                                   lotNumber = lotNumber.substring(0, lotNumber.indexOf("_"));
                               }
                               //System.out.println("Pretest_Out lotNumber = " + lotNumber);
                           }
                           String psType = null;
                           String currentLocation = null;
                           String nextProcess = null;
                           if ("BG_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) || "BFG_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = LOCATION_TYPE_BACK_GRIND;
                               currentLocation = LOCATION_TYPE_WAFER_STORE;
                               nextProcess =  LOCATION_TYPE_SORT;
                           }
                           else if ("Pretest_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = LOCATION_TYPE_PRE_TEST;
                               currentLocation = LOCATION_TYPE_CLASS_STORE;
                               nextProcess =  LOCATION_TYPE_FT;
                           }
                           else if ("FG_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = LOCATION_TYPE_PRE_TEST;
                               currentLocation = LOCATION_TYPE_CLASS_STORE;
                               nextProcess =  LOCATION_TYPE_FT;
                           }
                           else if ("TRES_IN".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = WIP_TEST_TYPE_FT;
                               currentLocation = WIP_TYPE_TEST;
                               nextProcess =  LOCATION_TYPE_TAPE_REEL;
                           }
                           else if ("TRES_OUT".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = LOCATION_TYPE_TAPE_REEL;
                               currentLocation = LOCATION_TYPE_CLASS_STORE;
                               nextProcess =  LOCATION_TYPE_TAPE_REEL;
                           }
                           else if ("Die_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = LOCATION_TYPE_DIE_BANK;
                               currentLocation = LOCATION_TYPE_DIE_BANK;
                               nextProcess =  LOCATION_TYPE_ASSEMBLY;
                           }
                           else if ( "FT_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = WIP_TEST_TYPE_FT;
                               currentLocation = WIP_TYPE_TEST;
                               nextProcess =  LOCATION_TYPE_TAPE_REEL;
                           }
                           else if ("ASSEMBLY_OUT".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = WIP_TYPE_ASSEMBLY;
                               currentLocation = WIP_TYPE_ASSEMBLY;
                               nextProcess =  LOCATION_TYPE_PRE_TEST;
                           }
                           else if ("TR_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               psType = LOCATION_TYPE_TAPE_REEL;
                               currentLocation = LOCATION_TYPE_CLASS_STORE;
                               nextProcess =  LOCATION_TYPE_FG;
                           }

                           if ( "Die_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               shippedLot = ( ShippedLot ) m_shipQtyOutDataMap.get ( partNumber + fabLotNo + transDate+adaptor.getDieQty() );

                               if ( shippedLot == null )
                               {
                                    shippedLot = new ShippedLot();
                                    m_shipQtyOutDataMap.put( partNumber + fabLotNo + transDate+adaptor.getDieQty(), shippedLot );
                               }
                           }
                           else if ( "BG_Out".equalsIgnoreCase( adaptor.getTransactionCode() )  || "BFG_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               shippedLot = ( ShippedLot ) m_shipQtyOutDataMap.get ( partNumber + fabLotNo + transDate+ adaptor.getWaferNo() );

                               if ( shippedLot == null )
                               {
                                    shippedLot = new ShippedLot();
                                    m_shipQtyOutDataMap.put( partNumber + fabLotNo + transDate+ adaptor.getWaferNo(), shippedLot );
                               }
                           }
                           else
                           {
                               shippedLot = ( ShippedLot ) m_shipQtyOutDataMap.get ( partNumber + lotNumber + psType + transDate+adaptor.getDieQty() );

                               if ( shippedLot == null )
                               {
                                    shippedLot = new ShippedLot();
                                    m_shipQtyOutDataMap.put( partNumber + lotNumber + psType + transDate+adaptor.getDieQty(), shippedLot );
                               }
                           }


                           int quantity = 0;
                           if ( "BG_Out".equalsIgnoreCase( adaptor.getTransactionCode() )  || "BFG_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               if ( shippedLot.getShipQty() != null )
                               {
                                   try
                                   {
                                       quantity = Integer.parseInt( shippedLot.getShipQty() );
                                   }
                                   catch ( NumberFormatException ignore )
                                   {
                                       quantity = 0;
                                   }
                                   quantity += 1;

                               }
                               else
                               {
                                 quantity = 1;
                               }
                           }
                           else
                           {
                               if ( shippedLot.getShipQty() != null )
                               {
                                   try
                                   {
                                       quantity = Integer.parseInt( shippedLot.getShipQty() );
                                   }
                                   catch ( NumberFormatException ignore )
                                   {
                                       quantity = 0;
                                   }
                                   quantity += adaptor.getDieQty();

                               }
                               else
                               {
                                 quantity = adaptor.getDieQty();
                               }
                           }
                            if ( shippedLot.getWaferID() != null )
                            {
                                allWafers = shippedLot.getWaferID() + ";" + adaptor.getWaferNo();
                            }
                            else
                            {
                                allWafers = adaptor.getWaferNo()+"";
                            }

                           if ( quantity > 0 )
                           {
                               if ("TRES_OUT".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                   shippedLot.setBatchingLot( adaptor.getBachingLot() );
                               }                               
                               if ("Die_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) || "BG_Out".equalsIgnoreCase( adaptor.getTransactionCode() )  || "BFG_Out".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                   shippedLot.setFabLotNumber( fabLotNo );
                                   shippedLot.setLotNumber( fabLotNo );
                                   shippedLot.setWaferID( allWafers );
                               }
                               else
                               {
                                  shippedLot.setLotNumber( lotNumber );
                               }
                               shippedLot.setProcessType(psType);
                               shippedLot.setCurrentLocation(currentLocation);
                               shippedLot.setNextProcess( nextProcess );
                               shippedLot.setTransactionType( adaptor.getTransactionCode() );
                               shippedLot.setVendorName(VENDOR_NAME_UTAC);
                               shippedLot.setPartNumber( partNumber );
                               shippedLot.setShipDate(transDate);
                               shippedLot.setShipQty( quantity + "" );
                               shippedLot.setNextLocation(adaptor.getShipLocation());
                           }
                       }

                       //Received QTY TRANSACTIONS
                       if ( adaptor.getTransactionCode() != null &&
                         ( "Assembly_In".equalsIgnoreCase( adaptor.getTransactionCode() ) || "Pretest_In".equalsIgnoreCase( adaptor.getTransactionCode() )
                            || "FT_IN".equalsIgnoreCase( adaptor.getTransactionCode() ) || "TR_In".equalsIgnoreCase( adaptor.getTransactionCode() )
                            || "TRES_In".equalsIgnoreCase( adaptor.getTransactionCode() ) /*|| "Die_In".equalsIgnoreCase( adaptor.getTransactionCode() )*/
                            || "TFG_In".equalsIgnoreCase( adaptor.getTransactionCode() ) ) || "BG_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                       {
								String psType = null;
                               if ("BG_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                    psType = LOCATION_TYPE_BACK_GRIND;
                               }
                               else if ("Pretest_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                    psType = LOCATION_TYPE_PRE_TEST;
                               }
                               else if ("Die_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                    psType =LOCATION_TYPE_DIE_BANK;
                               }
                               else if ("TFG_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                    psType =LOCATION_TYPE_FG;
                               }
                               else if ( "FT_IN".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                    psType= WIP_TEST_TYPE_FT;
                               }
                               else if ("Assembly_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                   psType = WIP_TYPE_ASSEMBLY;
                               }
                               else if ("TR_In".equalsIgnoreCase( adaptor.getTransactionCode() ) || "TRES_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                   psType = LOCATION_TYPE_TAPE_REEL;
                               }

                           int assyQtyIn = 0;
                           if ("Assembly_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                           {
                               assemblyLot = (AssemblyLot) m_receiveQtyInMap.get( partNumber + lotNumber + transDate + adaptor.getLotDieQty() );

                               if (assemblyLot == null)
                               {
                                   assemblyLot = new AssemblyLot( VENDOR_NAME_UTAC);
                                   m_receiveQtyInMap.put( partNumber + lotNumber + transDate + adaptor.getLotDieQty() , assemblyLot );

                                   assyQtyIn = adaptor.getLotDieQty();
                               }
                           }
                           else
                           {
                                if ("BG_In".equalsIgnoreCase( adaptor.getTransactionCode() ) || "Die_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                                {                                      
                                   assemblyLot = (AssemblyLot) m_receiveQtyInMap.get( partNumber + fabLotNo + transDate );

                                   if (assemblyLot == null)
                                   {
                                       assemblyLot = new AssemblyLot( VENDOR_NAME_UTAC);
                                       m_receiveQtyInMap.put( partNumber + fabLotNo+ transDate , assemblyLot );
                                   }
                                }
                                else
                                {
                                   assemblyLot = (AssemblyLot) m_receiveQtyInMap.get( partNumber + lotNumber + transDate + psType );

                                   if (assemblyLot == null)
                                   {
                                       assemblyLot = new AssemblyLot( VENDOR_NAME_UTAC);
                                       m_receiveQtyInMap.put( partNumber + lotNumber+ transDate + psType, assemblyLot );
                                   }
                                }
                                if ("BG_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                                {
                                    if ( assemblyLot.getQtyIn() != null)
                                    {
                                       try
                                       {
                                           assyQtyIn = Integer.parseInt( assemblyLot.getQtyIn() );
                                       }
                                       catch ( NumberFormatException ignore )
                                       {
                                           assyQtyIn = 0;
                                       }
                                       assyQtyIn += 1;
                                    }
                                    else
                                    {
                                       assyQtyIn = 1;
                                    }
                                }
                                else
                                {
                                    if ( assemblyLot.getQtyIn() != null)
                                    {
                                       try
                                       {
                                           assyQtyIn = Integer.parseInt( assemblyLot.getQtyIn() );
                                       }
                                       catch ( NumberFormatException ignore )
                                       {
                                           assyQtyIn = 0;
                                       }
                                       assyQtyIn += adaptor.getDieQty();
                                    }
                                    else
                                    {
                                       assyQtyIn = adaptor.getDieQty();
                                    }
                                }
                            }
                            if ( assemblyLot.getWaferIds() != null )
                            {
                                allWafers = assemblyLot.getWaferIds() + ";" + adaptor.getWaferNo();
                            }
                            else
                            {
                                allWafers = adaptor.getWaferNo()+"";
                            }
                           if ( assyQtyIn > 0 )
                           {	
                               assemblyLot.setProcessType( psType );
                               assemblyLot.setQtyIn( assyQtyIn +"");
                               assemblyLot.setDateIn( transDate );
                               if ("BG_In".equalsIgnoreCase( adaptor.getTransactionCode() ) || "Die_In".equalsIgnoreCase( adaptor.getTransactionCode() ) )
                               {
                                    assemblyLot.setLotNumber( fabLotNo );
									assemblyLot.setFabLotNumber( fabLotNo );
                                    assemblyLot.setWaferIds(allWafers);
                               }
                               else
                               {
                                   assemblyLot.setLotNumber( lotNumber );
                               }
                               assemblyLot.setDeviceName( partNumber );
                           }
                       }
                    }
                }
            }
        }
        catch(Exception ex)
        {
            System.out.println("ERROR!!!ERROR!!! While Parsing the UTAC Transaction Report");
            ex.printStackTrace();
            throw ex;
        }
    }

    private static void log( String message )
    {
        if ( message == null ) return;

        if ( m_parserLogger != null )
        {
            synchronized ( m_parserLogger )
            {
                m_parserLogger.logDebug( message + LINE_SEPARATOR );
            }
        }
        else
        {
            System.out.println( message );
        }
    }
}
